<template>
  <!--对话框：选择采购申请单-->
  <el-dialog v-dialogDrag v-dialogDragWidth :title="dialog_selectPosition.title"
             :visible.sync="dialog_selectPosition.visible"
             width="1100px" append-to-body>
    <!-- 检索条件 -->
    <el-form :model="dialog_selectPosition.queryParams"
             :inline="true" v-show="dialog_selectPosition.showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="docNum">
        <el-input
          v-model="dialog_selectPosition.queryParams.docNum"
          placeholder="请输入单据编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="getList_stockPosition">搜索</el-button>
      </el-form-item>

    </el-form>
    <!-- 采购申请列表 -->
    <el-table
      :data="dialog_selectPosition.stockPositionList"
      row-key="itemUuid"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="仓位编码" align="center" prop="stockPosCode" />
      <el-table-column label="仓位名称" align="center" prop="stockPosName" />
      <el-table-column label="状态" align="center" prop="sysNormalDisable">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.sysNormalDisable"/>
        </template>
      </el-table-column>
      <el-table-column label="请选择" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="success"
                     plain
                     size="small"
                     icon="el-icon-check"
                     @click="selectStockPosition_done(scope.row)"
          ><span>选择</span></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页查询 -->
    <pagination
      v-show="dialog_selectPosition.total>0"
      :total="dialog_selectPosition.total"
      :page.sync="dialog_selectPosition.queryParams.pageNum"
      :limit.sync="dialog_selectPosition.queryParams.pageSize"
      @pagination="getList_stockPosition"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog_hide_selectStockPosition">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { listStockPosition } from "@/api/wms/stockPosition";
  export default {
    dicts: ['sys_normal_disable','oa_dict_confirm_status'],
    data() {
      return {
        dialog_selectPosition: {
          visible: false,
          showSearch: true,
          title: "请选择物料",
          total: 0,
          stockPositionList: [],
          queryParams:{
            itemName: null,
          }
        },
        // 遮罩层
        loading: true,
        // 遮罩层
        visible: false,
        stockPosUuid:'',
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          phonenumber: undefined
        },
      };
    },
    methods: {
      /** 读取列表：物料 */
      getList_stockPosition() {
        this.loading = true;
        console.log(this.stockPosUuid)
        this.queryParams.stockPosUuid = this.stockPosUuid
        listStockPosition(this.queryParams).then(response => {
          this.dialog_selectPosition.stockPositionList = response.rows;
          this.dialog_selectPosition.total = response.total;
          this.loading = false;
        });
      },

      /**完成：选择物料*/
      selectStockPosition_done(stockPosition){
        this.dialog_selectPosition.visible = false;
        this.$emit("ok", stockPosition );
        console.log( stockPosition )

      },

      /**对话框：显示 - 选择采购单*/
      dialog_show_stockPosition() {
        this.getList_stockPosition()
        this.dialog_selectPosition.visible = true;
        this.dialog_selectPosition.title = "选择仓位";
      },

      /**对话框：隐藏 - 选择采购单*/
      dialog_hide_selectStockPosition() {
        this.dialog_selectPosition.visible = false;
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
